
axios.defaults.baseURL = 'http://www.itcbc.com:3006'

axios.interceptors.request.use(function (config) {
  
  if (config.url.startsWith('/user/')) {
    config.headers.Authorization = localStorage.getItem('mytoken')
  }
  return config;
}, function (error) {
  return Promise.reject(error);
});

axios.interceptors.response.use(
  function (response) {
    if (response.data.status === 1) {
      alert(response.data.message)
    }
    return response;
  },
  function (error) {
   
    if (error.response) {
      if (error.response.status === 401) {
        localStorage.removeItem('mytoken') 
        location.href = './login.html'
      }
      if (error.response.data.status === 1) {
        alert(error.response.data.message)
      }
    }
    return Promise.reject(error);
  }
);